import { useDetail, useList } from "@/hooks";
import { getUserInfoUrl } from "@/command/apiTool";
import { getAction } from "@/command/netTool";
import * as vant from "vant";
const { showFailToast, showSuccessToast } = vant;
export const useRequest = () => {
  // 我的保供任务
  const [listOpen, listOpenControl] = useDetail(
    getUserInfoUrl({
      dh: "/api/H5/richHelpGuaranteedSupplyTask/large/listOpen",
      xh: "/api/H5/richHelpGuaranteedSupplyTask/small/listResult",
    }),
    []
  );
  const btnAction = (url: any, params: any) => {
    getAction(url, { ...params }, { isResolve: true }).then((e) => {
      console.log("eee", e);
      showSuccessToast(e.msg);
      // 刷新接口
      listOpenControl.refresh();
    });
  };
  const accept = (id: any, status: any) => {
    let Url = {
      dh: "/api/H5/richHelpGuaranteedSupplyTask/large/accept",
      xh: "/api/H5/richHelpGuaranteedSupplyTask/small/acceptOrRefuse",
    };
    btnAction(getUserInfoUrl(Url), { taskId: id, status: status });
  };
  const refuse = (id: any, status: any) => {
    let Url = {
      dh: "/api/H5/richHelpGuaranteedSupplyTask/large/refuse",
      xh: "/api/H5/richHelpGuaranteedSupplyTask/small/acceptOrRefuse",
    };
    btnAction(getUserInfoUrl(Url), { taskId: id, status: status });
  };
  return {
    listOpen,
    accept,
    refuse,
  };
};
